package com.lovely602.langchain4j.functioncalling.service;


import com.fasterxml.jackson.databind.JsonNode;
import dev.langchain4j.agent.tool.P;
import dev.langchain4j.agent.tool.Tool;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 *
 * @author lizhixing
 */
@Slf4j
@Component
public class WeatherHandler {

    @Autowired
    private WeatherService weatherService;

    @Tool(name = "天气查询", value = "根据用户提供的地址信息查询天气")
    public String queryWeather(@P("地址") String location) throws Exception {
        log.info("location =>>>> {} ", location);
        //----------------------------------
        // 这块写自己的业务逻辑，调用redis/rabbitmq/kafka/mybatis/顺丰单据/医疗化验报告/支付接口等第3方
        //----------------------------------
        JsonNode weather = weatherService.getWeather(location);

        System.out.println(weather);

        return weather.toPrettyString();
    }

}
